package com.techfengs.test17;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class TestServer {//{{{
	public static void main (String[] args) throws IOException {//{{{
		System.out.println("服务器启动……");
		// => 创建套接字 ------------------------------------------------------------{{{
		ServerSocket ss = new ServerSocket(8888);
		//}}}
		// => 等待客户端连接 ------------------------------------------------------------{{{
		Socket s = ss.accept();
		//}}}
		// => 创建流 ------------------------------------------------------------{{{
		InputStream is = s.getInputStream();
		DataInputStream dis = new DataInputStream(is);
		OutputStream os = s.getOutputStream();
		DataOutputStream dos = new DataOutputStream(os);
//}}}
		// => 服务器端接收数据 ------------------------------------------------------------{{{
		String str = dis.readUTF();
		System.out.println(str);
		//}}}
		// => 服务器端发送数据 ------------------------------------------------------------{{{
		dos.writeUTF("你好，客户端，我接收到你的信息了");
		//}}}
		// => 关闭资源 ------------------------------------------------------------{{{
		// 关闭流
		dis.close();
		is.close();
		dos.close();
		os.close();
		// 关闭套接字
		s.close();
		ss.close();
		//}}}
	}
//}}}
}
//}}}
